<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\admin\service\AdminAdmin as S;
use think\captcha\facade\Captcha;
use think\facade\Request;

class Login extends Base
{
    //后台登录
    public function index()
    {
        global $globalConfig;
        //是否已经登录
        if (S::isLogin()) {
            return redirect(Request::root() . '/index');
        }
        if (Request::isAjax()) {
            $this->getJson(S::login(Request::param()));
        }
        return $this->fetch('', [
            'login_captcha' => $globalConfig['login_captcha']
        ]);
    }

    // 验证码
    public function verify()
    {
        ob_clean();
        return Captcha::create();
    }

    //退出登陆
    public function logout()
    {
        return $this->getJson(S::logout());
    }
}
